home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / x / srgp_sta.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-11  |  5.1 KB  |  190 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** X11 VERSION OF state.c
  5. This contains no conditionally compiled code because it should be used
  6. only in the X11 version.
  7. **/
  8.  
  9.  
  10. static XWindowAttributes    srgpx__windowattrs;
  11. static XSetWindowAttributes    srgpx__setwindowattrs;
  12. static XSizeHints         srgpx__sizehints;
  13. static XWMHints            wm_hints;
  14.  
  15.  
  16. /** ERROR HANDLER FOR X SERVER EXCEPTIONS
  17. **/
  18.  
  19. int SRGP__handlerForXerrors (Display *d, XErrorEvent *err)
  20. {
  21.    char msg[80];
  22.  
  23.    XGetErrorText (d, err->error_code, msg, 80);
  24.    SRGP__error (ERR_X_SERVER, msg);
  25. }
  26.  
  27.  
  28.  
  29. void SRGP__initGraphicsDevice 
  30.    (char *name, int requested_planes, boolean debugasap)
  31. {
  32.    int cnt, i, j;
  33.    int width, height;
  34.    XEvent report;
  35.  
  36.    if ( (srgpx__display = XOpenDisplay(0)) == 0) {
  37.       fprintf (stderr, "unable to open to x server.\n");
  38.       exit(1);
  39.    }
  40.    
  41.    if (debugasap)
  42.       SRGP_enableSynchronous();
  43.       
  44.    XSetErrorHandler (SRGP__handlerForXerrors);
  45.  
  46.    srgpx__screen = DefaultScreen(srgpx__display);
  47.  
  48.    /* CREATE WINDOW FOR VIRTUAL SCREEN (canvas #0) */
  49.    srgp__curActiveCanvasSpec.drawable.win =
  50.       XCreateSimpleWindow (srgpx__display,
  51.                RootWindow(srgpx__display,srgpx__screen), 0,0,
  52.                width=srgp__curActiveCanvasSpec.max_xcoord+1,
  53.                height=srgp__curActiveCanvasSpec.max_ycoord+1,
  54.                1, 0L, 0L);
  55.  
  56.    SRGP__initColor (requested_planes);
  57.  
  58.  
  59.    /* SET GRAPHICS CONTEXT */
  60.    srgp__curActiveCanvasSpec.gc_frame =
  61.       XCreateGC (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  62.          0L, NULL);
  63.    srgp__curActiveCanvasSpec.gc_fill =
  64.       XCreateGC (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  65.          0L, NULL);
  66.  
  67.    /* INIT INPUT */
  68.    XSelectInput
  69.       (srgpx__display, srgp__curActiveCanvasSpec.drawable.win, 
  70.        ExposureMask|PropertyChangeMask);
  71.  
  72.    /* SET 0th CANVAS-WINDOW PROPERTIES */
  73.    srgpx__sizehints.flags = PSize | PMinSize | PMaxSize;
  74.    srgpx__sizehints.width = width;     srgpx__sizehints.height = height;
  75.    srgpx__sizehints.min_width = width; srgpx__sizehints.min_height = height;
  76.    srgpx__sizehints.max_width = width; srgpx__sizehints.max_height = height;
  77.    XSetStandardProperties
  78.       (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  79.        name, name, 0, 0, 0, &srgpx__sizehints);
  80.    wm_hints.flags = InputHint;
  81.    wm_hints.input = TRUE;
  82.    XSetWMHints (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  83.         &wm_hints);
  84.  
  85.    /* MAP...  Wait for the expose and property events */
  86.    XMapWindow (srgpx__display, srgp__curActiveCanvasSpec.drawable.win);
  87.    i=0; j=0;
  88.  
  89.    do {
  90.       XNextEvent (srgpx__display, &report);
  91.       switch (report.type) {
  92.        case Expose:
  93.      if (report.xexpose.count == 0) i++; break;
  94.        case PropertyNotify:
  95.      j++; srgpx__starttime = srgpx__cur_time = report.xproperty.time; 
  96.      break;
  97.       }
  98.    } while (i==0 || j==0);
  99.  
  100.    /* No need for catching property events any more. */
  101.    XSelectInput
  102.       (srgpx__display, srgp__curActiveCanvasSpec.drawable.win, 
  103.                                     ExposureMask);
  104.  
  105.    /* We set up for backing store. */
  106.   srgpx__setwindowattrs.backing_store = Always;
  107.  
  108.    XChangeWindowAttributes
  109.       (srgpx__display,
  110.        srgp__curActiveCanvasSpec.drawable.win,
  111.        CWBackingStore, &srgpx__setwindowattrs);
  112. }
  113.  
  114.  
  115.  
  116.  
  117. /** SRGP_refresh
  118. **/
  119.  
  120. void
  121. SRGP_refresh ()
  122. {
  123.    XSync (srgpx__display, FALSE);
  124.    SRGP__handleRawEvents (FALSE,FALSE);
  125. }
  126.  
  127.  
  128.  
  129. /** SRGP_enableSynchronous
  130. For use by a system administrator only.
  131. Puts X into synch. mode.
  132. **/
  133.  
  134. void
  135. SRGP_enableSynchronous ()
  136. {
  137.    XSynchronize (srgpx__display, 1);
  138.    XSync (srgpx__display, FALSE);
  139. }
  140.  
  141.  
  142.  
  143. /*!*/
  144.  
  145. static boolean resize_allowed = FALSE;
  146.  
  147. static void
  148. InformWindowManagerOfResizeStrategy()
  149. {
  150.    if (resize_allowed) {
  151.       srgpx__sizehints.flags = PMinSize | PMaxSize | PResizeInc;
  152.       srgpx__sizehints.min_width = 5; srgpx__sizehints.min_height = 5;
  153.       srgpx__sizehints.max_width = 5000; srgpx__sizehints.max_height = 5000;
  154.       srgpx__sizehints.width_inc = 1; srgpx__sizehints.height_inc = 1;
  155.       XSetStandardProperties
  156.      (srgpx__display, srgp__canvasTable[0].drawable.win,
  157.       NULL, NULL, 0, 0, 0, &srgpx__sizehints);
  158.    }
  159.    else {
  160.       int width = srgp__canvasTable[0].max_xcoord + 1;
  161.       int height = srgp__canvasTable[0].max_ycoord + 1;
  162.       srgpx__sizehints.flags = PSize | PMinSize | PMaxSize;
  163.       srgpx__sizehints.width = width;     srgpx__sizehints.height = height;
  164.       srgpx__sizehints.min_width = width; srgpx__sizehints.min_height = height;
  165.       srgpx__sizehints.max_width = width; srgpx__sizehints.max_height = height;
  166.       XSetStandardProperties
  167.      (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  168.       NULL, NULL, 0, 0, 0, &srgpx__sizehints);
  169.    }
  170. }
  171.  
  172.  
  173. void
  174. SRGP_allowResize (boolean allow)
  175. {
  176.    resize_allowed = allow;
  177.    InformWindowManagerOfResizeStrategy();
  178. }
  179.  
  180.  
  181. void
  182. SRGP__forceScreenResize (int newwidth, int newheight)
  183. {
  184.    XResizeWindow (srgpx__display, srgp__canvasTable[0].drawable.win,
  185.           newwidth, newheight);
  186.    srgp__canvasTable[0].max_xcoord = newwidth - 1;
  187.    srgp__canvasTable[0].max_ycoord = newheight - 1;
  188.    InformWindowManagerOfResizeStrategy();
  189. }
  190.